
package helpdesk;

import database.Announcement;
import database.DatabaseInteraction;
import database.PDFHandler;
import database.Query;
import java.awt.event.ActionEvent;
import java.io.*;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;

public class StudentInterface extends CenteredFrame {

    private String currentUser;
    MyTableModel queryModel;
    MyTableModel announcementModel;
    MyTableModel formStatusModel;
    String[][] forms;
    Query[] queries;
    Announcement[] announcements;
    Object[][] queryData;
    Object[][] announcementData;

    public StudentInterface() {
        initComponents();
        currentUser = "hidden";
    }

    public StudentInterface(String currentUser) {
        this.currentUser = currentUser;
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnPostToGroup = new javax.swing.ButtonGroup();
        formUploader = new javax.swing.JFileChooser();
        queRespFrame = new CenteredFrame();
        jScrollPane4 = new javax.swing.JScrollPane();
        viewQueRespTextArea = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        submitQueRespTextArea = new javax.swing.JTextArea();
        submitQueRespBtn = new javax.swing.JToggleButton();
        formStatusFrame = formStatusFrame = new CenteredFrame();
        formStatusScrollPane = new javax.swing.JScrollPane();
        formStatusTable = new javax.swing.JTable();
        formOpenButton = new javax.swing.JButton();
        submitQueryButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        uploadFormButton = new javax.swing.JButton();
        formStatusButton = new javax.swing.JButton();
        viewQueRespBtn = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        postAllRadioButton = new javax.swing.JRadioButton();
        postGARadioButton = new javax.swing.JRadioButton();
        jComboBox1 = new javax.swing.JComboBox();
        queriesScrollPane = new javax.swing.JScrollPane();
        queriesTable = new javax.swing.JTable();
        announcementsScrollPane = new javax.swing.JScrollPane();
        announcementsTable = new javax.swing.JTable();

        formUploader.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formUploaderActionPerformed(evt);
            }
        });

        viewQueRespTextArea.setColumns(20);
        viewQueRespTextArea.setEditable(false);
        viewQueRespTextArea.setLineWrap(true);
        viewQueRespTextArea.setRows(5);
        viewQueRespTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Query"));
        jScrollPane4.setViewportView(viewQueRespTextArea);

        submitQueRespTextArea.setColumns(20);
        submitQueRespTextArea.setRows(5);
        submitQueRespTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Response"));
        jScrollPane5.setViewportView(submitQueRespTextArea);

        submitQueRespBtn.setText("Submit");
        submitQueRespBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitQueRespBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout queRespFrameLayout = new org.jdesktop.layout.GroupLayout(queRespFrame.getContentPane());
        queRespFrame.getContentPane().setLayout(queRespFrameLayout);
        queRespFrameLayout.setHorizontalGroup(
            queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(queRespFrameLayout.createSequentialGroup()
                .add(14, 14, 14)
                .add(queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane4)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, submitQueRespBtn))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        queRespFrameLayout.setVerticalGroup(
            queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(queRespFrameLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(submitQueRespBtn)
                .addContainerGap())
        );

        formStatusFrame.setTitle("View Form Status");

        formStatusModel = new MyTableModel();
        formStatusScrollPane.setViewportView(formStatusTable);

        formOpenButton.setText("Open");
        formOpenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formOpenButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout formStatusFrameLayout = new org.jdesktop.layout.GroupLayout(formStatusFrame.getContentPane());
        formStatusFrame.getContentPane().setLayout(formStatusFrameLayout);
        formStatusFrameLayout.setHorizontalGroup(
            formStatusFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, formStatusFrameLayout.createSequentialGroup()
                .add(formStatusScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(formOpenButton)
                .addContainerGap())
        );
        formStatusFrameLayout.setVerticalGroup(
            formStatusFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(formStatusScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)
            .add(formStatusFrameLayout.createSequentialGroup()
                .add(43, 43, 43)
                .add(formOpenButton)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Help Desk - Student");

        submitQueryButton.setText("Submit");
        submitQueryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitQueryButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Options"));

        uploadFormButton.setText("Upload Forms");
        uploadFormButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadFormButtonActionPerformed(evt);
            }
        });

        formStatusButton.setText("Check Form Status");
        formStatusButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formStatusButtonActionPerformed(evt);
            }
        });

        viewQueRespBtn.setText("View/Reply to Query");
        viewQueRespBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewQueRespBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(uploadFormButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(formStatusButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(viewQueRespBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(13, 13, 13)
                .add(viewQueRespBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(uploadFormButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(formStatusButton)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTextArea1.setColumns(20);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setBorder(javax.swing.BorderFactory.createTitledBorder("Post Query"));
        jScrollPane2.setViewportView(jTextArea1);

        btnPostToGroup.add(postAllRadioButton);
        postAllRadioButton.setSelected(true);
        postAllRadioButton.setText("Post to All");

        btnPostToGroup.add(postGARadioButton);
        postGARadioButton.setText("Post to Graduate Assistant");
        postGARadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                postGARadioButtonActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Response to an Announcement", "Regarding Form Submission", "Rearding Help Desk", "Other" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        queriesScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Queries"));
        queriesScrollPane.setFocusable(false);
        queriesScrollPane.setRequestFocusEnabled(false);
        queriesScrollPane.setVerifyInputWhenFocusTarget(false);

        queryModel = new MyTableModel();
        queriesTable.setModel(formStatusModel);
        queriesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        queriesTable.setAutoscrolls(false);
        queriesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        queriesTable.getTableHeader().setReorderingAllowed(false);
        queriesScrollPane.setViewportView(queriesTable);
        updateQueries();

        announcementsScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Announcements"));

        announcementModel = new MyTableModel();//DefaultTableModel();
        announcements = DatabaseInteraction.getAllAnnouncements();
        announcementData = new Object[announcements.length][2];
        announcementModel.addColumn("User");
        announcementModel.addColumn("Announcement");
        for(int i=0;i<announcements.length;i++){
            announcementData[i][0] = announcements[i].getCreateBy();
            announcementData[i][1] = announcements[i].getContent();
        }
        announcementModel.setDataVector(announcementData, new Object[]{"User","Announcement"});
        announcementsTable.setModel(announcementModel);
        announcementsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        announcementsTable.setAutoscrolls(false);
        announcementsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        announcementsTable.getTableHeader().setReorderingAllowed(false);
        javax.swing.table.TableColumn colA = announcementsTable.getColumnModel().getColumn(0);
        colA.setPreferredWidth(250);
        javax.swing.table.TableColumn colB = announcementsTable.getColumnModel().getColumn(1);
        colB.setPreferredWidth(1000);
        announcementsScrollPane.setViewportView(announcementsTable);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(postGARadioButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(submitQueryButton))
                            .add(layout.createSequentialGroup()
                                .add(postAllRadioButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(queriesScrollPane)
                    .add(announcementsScrollPane))
                .add(31, 31, 31))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(17, 17, 17)
                        .add(announcementsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 157, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(queriesScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(16, 16, 16))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(postAllRadioButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(submitQueryButton)
                            .add(postGARadioButton)))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void submitQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitQueryButtonActionPerformed
        
        //check to make sure text is in query entry area
        // if so continue and create a query with username for created by, 
        //int from drop down for category, from radio for type, null for 
        //responses since first post, content from entry
        int type, category;
        String createdby, content, responses;
        if (!jTextArea1.getText().equals("")) {
            if (btnPostToGroup.isSelected(postAllRadioButton.getModel())) {
                type = 1;
            } else {
                type = 2;
            }
            category = jComboBox1.getSelectedIndex() + 1;
            createdby = currentUser;
            content = jTextArea1.getText();
            responses = "";
            database.Query query = new database.Query(0, type, category, createdby, content, responses);
            database.DatabaseInteraction.postQuery(query);
            updateQueries();
            resetForm();
        }
    }//GEN-LAST:event_submitQueryButtonActionPerformed

    private void formUploaderActionPerformed(java.awt.event.ActionEvent evt) {
    }

    private void postGARadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_postGARadioButtonActionPerformed
        
    }//GEN-LAST:event_postGARadioButtonActionPerformed

    private void submitQueRespBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitQueRespBtnActionPerformed
        int id = Integer.parseInt(queries[queriesTable.getSelectedRow()].get("id").toString());
        String response = queries[queriesTable.getSelectedRow()].get("responses") + "\n" + submitQueRespTextArea.getText();
        DatabaseInteraction.editQuery(id, "responses", response);
        updateQueries();
        queRespFrame.dispose();
    }//GEN-LAST:event_submitQueRespBtnActionPerformed

    private void viewQueRespBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewQueRespBtnActionPerformed
        if (queriesTable.isRowSelected(queriesTable.getSelectedRow()) && queries.length > queriesTable.getSelectedRow()) {
            queRespFrame.setSize(500, 350);
            queRespFrame.setVisible(true);
            String content = queries[queriesTable.getSelectedRow()].get("content").toString();
            String username = queries[queriesTable.getSelectedRow()].get("createdBy").toString();
            String responses = queries[queriesTable.getSelectedRow()].get("responses").toString();
            if (responses.length() == 0) {
                responses = "No responses posted";
            }
            viewQueRespTextArea.setText(username + ": " + content + "\nResponses:\n" + responses);
            submitQueRespTextArea.setText(currentUser + ": ");
            
        }
    }//GEN-LAST:event_viewQueRespBtnActionPerformed
    private void formStatusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formStatusButtonActionPerformed
        formStatusFrame.setVisible(true);
        formStatusFrame.setSize(300, 300);
        updateFormStatus();
    }//GEN-LAST:event_formStatusButtonActionPerformed

    private void formOpenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formOpenButtonActionPerformed
        try {
            String filename = forms[formStatusTable.getSelectedRow()][0];
            if (filename != null) {
                File file = DatabaseInteraction.getSelectedForm(currentUser,
                        filename);
                PDFHandler.open(file);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(GradAssInterface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(GradAssInterface.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ArrayIndexOutOfBoundsException e) {
            javax.swing.JOptionPane.showMessageDialog(null, "No Form Selected", "Form Error", javax.swing.JOptionPane.ERROR_MESSAGE, null);
        }
    }//GEN-LAST:event_formOpenButtonActionPerformed
    private void updateQueries() {
        queries = DatabaseInteraction.getAllQueries();
        ArrayList<Query> queries2 = new ArrayList<Query>();
        int valueType, valueCategory;
        for (int i = 0; i < queries.length; i++) {
            if ((queries[i].get("typeViewable").equals(1)) || (queries[i].get("createdby").equals(currentUser))) {
                queries2.add(queries[i]);
            }
        }
        queries = queries2.toArray(new Query[queries2.size()]);
        queryData = new Object[queries.length][2];
        for (int i = 0; i < queries.length; i++) {
            queryData[i][0] = queries[i].get("createdby");
            queryData[i][1] = queries[i].get("content");
        }
        queryModel.setDataVector(queryData, new Object[]{"User", "Query"});
        queriesTable.setModel(queryModel);
        queriesTable.setColumnSelectionAllowed(false);
        queriesTable.setMaximumSize(new java.awt.Dimension(1000, 500));
        queriesTable.setMinimumSize(new java.awt.Dimension(500, 100));
        queriesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        queriesTable.getTableHeader().setReorderingAllowed(false);
        queriesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        javax.swing.table.TableColumn col = queriesTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = queriesTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(1000);
        queriesScrollPane.setViewportView(queriesTable);
        queriesTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }

    private void updateFormStatus() {
        forms = DatabaseInteraction.getUserForms(currentUser);
        int i = 0;
        while (forms[i][0] != null) {
            if ("1".equals(forms[i][1])) {
                forms[i][1] = "Reviewed";
            } else {
                forms[i][1] = "Not Reviewed";
            }
            i++;
        }
        formStatusModel.setDataVector(forms, new Object[]{"Filename", "Status"});
        formStatusTable.setModel(formStatusModel);
        formStatusTable.setColumnSelectionAllowed(false);
        formStatusTable.setMaximumSize(new java.awt.Dimension(1000, 500));
        formStatusTable.setMinimumSize(new java.awt.Dimension(500, 100));
        formStatusTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        formStatusTable.getTableHeader().setReorderingAllowed(false);
        formStatusTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        javax.swing.table.TableColumn col = formStatusTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = formStatusTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(100);
        formStatusScrollPane.setViewportView(formStatusTable);
        formStatusTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }

    private void resetForm() {
        jTextArea1.setText("");
        postAllRadioButton.setSelected(true);
        jComboBox1.setSelectedIndex(0);
    }

    public void copyFiles(String source, String destination) throws IOException {
        File src = new File(source);

        FileChannel in = null;
        FileChannel out = null;
        try {
            in = new FileInputStream(src).getChannel();
            File outFile = new File(destination, src.getName());
            out = new FileOutputStream(outFile).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }

    private void uploadFormButtonActionPerformed(java.awt.event.ActionEvent evt) {
        int returnVal = formUploader.showOpenDialog(this);
        String filename;
        if (returnVal == formUploader.APPROVE_OPTION) {
            File file = formUploader.getSelectedFile();

            try {
                DatabaseInteraction.postForm(currentUser, file.getName(), file);
            } catch (Exception e) {
                javax.swing.JOptionPane.showMessageDialog(null, "Error writing file", "Error", javax.swing.JOptionPane.ERROR_MESSAGE, null);
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane announcementsScrollPane;
    private javax.swing.JTable announcementsTable;
    private javax.swing.ButtonGroup btnPostToGroup;
    private javax.swing.JButton formOpenButton;
    private javax.swing.JButton formStatusButton;
    private javax.swing.JFrame formStatusFrame;
    private javax.swing.JScrollPane formStatusScrollPane;
    private javax.swing.JTable formStatusTable;
    private javax.swing.JFileChooser formUploader;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JRadioButton postAllRadioButton;
    private javax.swing.JRadioButton postGARadioButton;
    private javax.swing.JFrame queRespFrame;
    private javax.swing.JScrollPane queriesScrollPane;
    private javax.swing.JTable queriesTable;
    private javax.swing.JToggleButton submitQueRespBtn;
    private javax.swing.JTextArea submitQueRespTextArea;
    private javax.swing.JButton submitQueryButton;
    private javax.swing.JButton uploadFormButton;
    private javax.swing.JButton viewQueRespBtn;
    private javax.swing.JTextArea viewQueRespTextArea;
    // End of variables declaration//GEN-END:variables
}
